package zhongbo.java.air.dictionary.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AlertZone;
import zhongbo.java.air.dictionary.service.IAlertZoneService;


@RestController
@RequestMapping("/alertZone")
@Api(tags = "警报信息")
public class AirZoneComtroller {

    @Autowired
    IAlertZoneService iAlertZoneService;
    @PostMapping("/insert")
    @ApiOperation("添加")
    public ResultVo<AlertZone> insert(@RequestBody AlertZone alertZone){
        AlertZone airPort1 =iAlertZoneService.insert(alertZone);
        return ResultVo.ok(airPort1);
    }

    @PostMapping("/delete")
    @ApiOperation("根据id删除全部信息")
    public ResultVo<String> delete( String id){
        String ok =iAlertZoneService.delete(id);
        return ResultVo.ok(ok);
    }

    @PostMapping("/update")
    @ApiOperation("更新")
    public ResultVo<AlertZone> update(@RequestBody AlertZone alertZone){
        AlertZone aa=iAlertZoneService.updateStatus(alertZone);
        if(aa==null){//数据不存在
            return ResultVo.failed();
        }
        return ResultVo.ok(alertZone);
    }
    //根据id查询
    @PostMapping("/select")
    @ApiOperation("查询")
    public ResultVo<AlertZone> select( String id){
        AlertZone alertZone =iAlertZoneService.select(id);
        return ResultVo.ok(alertZone);
    }


    @ResponseBody
    @RequestMapping(value = "/page", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "分页条件查询记录接口")
    public ResultVo<PageVo<AlertZone>> findPage(
            @RequestParam(required = false) String id
            , @RequestParam(required = false, defaultValue = "1") int pageNumber
            , @RequestParam(required = false, defaultValue = "10") int pageSize
    ) {
        PageVo<AlertZone> page = iAlertZoneService.findPage(id, pageNumber, pageSize);
        return ResultVo.ok(page);
    }




}
